home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrDlist<T> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tpdlist.h> RWTPtrDlist<T> list; PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt described in the Class Reference. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a collection of pointers to type TTTT, implemented as a doubly linked list. This is a pointer based list: pointers to objects are copied in and out of the links that make up the list. Parameter TTTT represents the type of object to be inserted into the list, either a class or fundamental type. The class TTTT must have: well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&))))). PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic EEEExxxxaaaammmmpppplllleeee In this example, a doubly-linked list of pointers to the user type DDDDoooogggg is exercised. Contrast this approach with the example given under RRRRWWWWTTTTVVVVaaaallllDDDDlllliiiisssstttt<<<<TTTT>>>>.... #include <rw/tpdlist.h> #include <rw/rstream.h> #include <string.h> class Dog { char* name; public: Dog( const char* c) { name = new char[strlen(c)+1]; strcpy(name, c); } ~Dog() { delete name; } // Define a copy constructor: Dog(const Dog& dog) { name = new char[strlen(dog.name)+1]; strcpy(name, dog.name); } // Define an assignment operator: void operator=(const Dog& dog) { if (this!=&dog) { PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) delete name; name = new char[strlen(dog.name)+1]; strcpy(name, dog.name); } } // Define an equality test operator: int operator==(const Dog& dog) const { return strcmp(name, dog.name)==0; } friend ostream& operator<<(ostream& str, const Dog& dog){ str << dog.name; return str;} }; main() { RWTPtrDlist<Dog> terriers; terriers.insert(new Dog("Cairn Terrier")); terriers.insert(new Dog("Irish Terrier")); terriers.insert(new Dog("Schnauzer")); Dog key1("Schnauzer"); cout << "The list " << (terriers.contains(&key1) ? "does " : "does not ") << "contain a Schnauzer0; Dog key2("Irish Terrier"); terriers.insertAt( terriers.index(&key2), new Dog("Fox Terrier") ); Dog* d; while (!terriers.isEmpty()) { d = terriers.get(); cout << *d << endl; delete d; } return 0; } Program output: The list does contain a Schnauzer Cairn Terrier Fox Terrier Irish Terrier Schnauzer PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt<T>(); Constructs an empty list. PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt<T>(const RWTPtrDlist<T>& c); Constructs a new doubly-linked list as a shallow copy of cccc. After construction, pointers will be shared between the two collections. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrDlist& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrDlist<T>& c); Sets self to a shallow copy of cccc. Afterwards, pointers will be shared between the two collections. T*& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i); T* const& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const; Returns a pointer to the iiiith value in the list. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppeeeennnndddd(T* a); Appends the item pointed to by aaaa to the end of the list. void aaaappppppppllllyyyy(void (*applyFun)(T*, void*), void* d); Applies the user-defined function pointed to by aaaappppppppllllyyyyFFFFuuuunnnn to every item in the list. This function must have the prototype: void yyyyoooouuuurrrrFFFFuuuunnnn(T* a, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. T*& aaaatttt(size_t i); T* const& PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) aaaatttt(size_t i) const; Returns a pointer to the iiiith value in the list. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. void cccclllleeeeaaaarrrr(); Removes all items from the collection. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all items from the collection aaaannnndddd deletes them. RWBoolean ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const; Returns TTTTRRRRUUUUEEEE if the list contains an object that is equal to the object pointed to by aaaa, FFFFAAAALLLLSSSSEEEE otherwise. Equality is measured by the class- defined equality operator for type TTTT. RWBoolean ccccoooonnnnttttaaaaiiiinnnnssss(RWBoolean (*testFun)(T*, void*),void* d) const; Returns TTTTRRRRUUUUEEEE if the list contains an item for which the user-defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE . Returns FFFFAAAALLLLSSSSEEEE otherwise. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. size_t eeeennnnttttrrrriiiieeeessss() const; Returns the number of items that are currently in the collection. PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) T* ffffiiiinnnndddd(const T* target) const; Returns a pointer to the first object encountered which is equal to the object pointed to by ttttaaaarrrrggggeeeetttt, or nnnniiiillll if no such object can be found. Equality is measured by the class-defined equality operator for type TTTT. T* ffffiiiinnnndddd(RWBoolean (*testFun)(T*, void*),void* d,) const; Returns a pointer to the first object encountered for which the user- defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or nnnniiiillll if no such object can be found. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. T*& ffffiiiirrrrsssstttt(); T* const& ffffiiiirrrrsssstttt() const; Returns a pointer to the first item in the list. The behavior is undefined if the list is empty. T* ggggeeeetttt(); Returns a pointer to the first item in the list and removes the item. The behavior is undefined if the list is empty. size_t iiiinnnnddddeeeexxxx(const T* a); Returns the index of the first object that is equal to the object pointed to by aaaa, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such object. Equality is measured by the class-defined equality operator for type TTTT. PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) size_t iiiinnnnddddeeeexxxx(RWBoolean (*testFun)(T*, void*),void* d) const; Returns the index of the first object for which the user-defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such object. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. void iiiinnnnsssseeeerrrrtttt(T* a); Adds the object pointed to by aaaa to the end of the list. void iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, T* a); Adds the object pointed to by aaaa at the index position iiii. This position must be between zero and the number of items in the list, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. RWBoolean iiiissssEEEEmmmmppppttttyyyy() const; Returns TTTTRRRRUUUUEEEE if there are no items in the list, FFFFAAAALLLLSSSSEEEE otherwise. T*& llllaaaasssstttt(); T* const& llllaaaasssstttt() const; Returns a pointer to the last item in the list. The behavior is undefined if the list is empty. size_t ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const; Returns the number of objects in the list that are equal to the object PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) pointed to by aaaa. Equality is measured by the class-defined equality operator for type TTTT. size_t ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(RWBoolean (*testFun)(T*, void*),void* d)const; Returns the number of objects in the list for which the user-defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE . The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. void pppprrrreeeeppppeeeennnndddd(T* a); Adds the item pointed to by aaaa to the beginning of the list. T* rrrreeeemmmmoooovvvveeee(const T* a); Removes the first object which is equal to the object pointed to by aaaa and returns a pointer to it, or nnnniiiillll if no such object could be found. Equality is measured by the class-defined equality operator for type TTTT. T* rrrreeeemmmmoooovvvveeee(RWBoolean (*testFun)(T*, void*),void* d); Removes the first object for which the user-defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE and returns a pointer to it, or nnnniiiillll if there is no such object. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) size_t rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a); Removes all objects which are equal to the object pointed to by aaaa. Returns the number of objects removed. Equality is measured by the class-defined equality operator for type TTTT. size_t rrrreeeemmmmoooovvvveeeeAAAAllllllll(RWBoolean (*testFun)(T*, void*),void* d); Removes all objects for which the user-defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE. Returns the number of objects removed. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. T* rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i); Removes the object at index iiii and returns a pointer to it. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if iiii is not a valid index. Valid indices are from zero to the number of items in the list less one. T* rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt(); Removes the first item in the list and returns a pointer to it. The behavior is undefined if the list is empty. T* rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt(); Removes the last item in the list and returns a pointer to it. The behavior is undefined if the list is empty. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrDlist<T>& coll); RWFile& PPPPaaaaggggeeee 8888 RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++)))) ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrDlist<T>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrDlist<T>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrDlist<T>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrDlist<T>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrDlist<T>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999